'''
    This file is part of Ognom Keeper.

    Ognom Keeper is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ognom Keeper is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ognom Keeper.  If not, see <http://www.gnu.org/licenses/>.


    Copyright(C) 2009 Viktor Vestberg
'''

from handlers import *

class PlayerFactory:
    """This class simply creates a player easily for us. It creates all the necessary Parts and put it all together to a shiny new player"""
    def __init__(self, entityHandler, renderer, physics, input):
        self.entityHandler = entityHandler
        self.renderer = renderer
        self.physics = physics
        self.input = input
        self.aligner = None
        self.bgRect = pygame.display.get_surface().get_rect()
        self.players = []
        self.mouseAligners = []
    def makePlayer(self, position=None, visible=None):#, verts=[(-8,-5),(-8,5),(8,5),(8,-5)]):
        if position is None:
           mp = pygame.mouse.get_pos()
           position = (mp[0]+self.bgRect.left, mp[1]+self.bgRect.top)
           
        entity = self.entityHandler.makeEntity(position)
        physicPart = self.physics.makeBallpart()
        physicPart.body.angle = to_radian(270)
        #renderable = self.renderer.makeCircle()
        renderable = self.renderer.makePart('ball.png')
        #event = ObserverEvent()
        #jumpkey = self.input.makeKeypart(pygame.K_SPACE, [event.activate])
        #event.addEvent(physicPart.jump)
        #inputPart = self.input.makePart([jumpkey])
        
        entity.addParts([renderable, physicPart])#, inputPart])
        self.players.append(entity)
        return entity
    
    def clean(self):
        for entity in self.players: entity.handler.removeEntity(entity)
        self.players = []
    def setBgRect(self, rect):
        self.bgRect = rect
    def setBgSurface(self, surf):
        self.bgSurf = surf
    def setBgPicture(self, pic):
        self.bgPic = pic

class WallFactory:
    """This class creates walls easily for us"""
    def __init__(self, entityHandler, renderer, physics):
        self.entityHandler = entityHandler
        self.renderer = renderer
        self.physics = physics
        self.walls = []
        self.finishList = []
        self.badWalls = []
    def makeWall(self, verticies=[(1,1,(2,2))], color=[0,0,0], visible=False, colType=2, elasticy=2.1):
        entity = self.entityHandler.makeEntity()
        PhysicsPart = self.physics.makeWallpart(verticies, 1e100, colType, elasticy)
        if visible: 
            RenderPart = self.renderer.makeLine(color)
            entity.addParts([PhysicsPart, RenderPart])
        else: entity.addParts([PhysicsPart])
        self.walls.append(entity)
        return entity
    def clean(self):
        for wall in self.walls: wall.handler.removeEntity(wall)
        for wall in self.finishList: wall.handler.removeEntity(wall)
        self.renderer.cleanBlit()

